<?php
use yii\helpers\Html;
use yii\helpers\Url;
use app\lib\WeixinUtils;

/* @var $this yii\web\View */
/* @var $content string 字符串 */


$web = Url::to("@web");

//var_dump($card);
//die;
$viewGooods = [];
$tmp = [];
$m = 0;
//$goods_count=count($goods);
//for($i = 0; $i < $goods_count; ++$i){
//
//    $tmp[]=$goods[$i];
//    $m=$m+1;
//    if($m==2 || $i==$goods_count-1){
//        $viewGooods[]=$tmp;
//        $m=0;
//        $tmp=[];
//    }
//}
//var_dump($viewGooods);
//die;

?>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">

    <link rel="stylesheet" href="<?= $web ?>/css/wx/new_card_list.css"/>
    <script type="application/javascript" src="<?= $web ?>/js/jquery.js"></script>
    <script type="application/javascript" src="<?= $web ?>/js/wx/pager.js"></script>
    <script type="application/javascript" src="<?= $web ?>/js/tools.js"></script>
    <script type="text/javascript">
            $(document).ready(function () {
                var w = $(document).width();
                if (w > 640) {
                    w = 640;
                }
            $("body").css("font-size", w * 100 / 320);

            $(".buy-fold-frame").click(function () {
                $(".buy-fold-frame").hide();
                $(".buy-mask").show();
                $(".buy-unfold-frame").show();

                isPager = false;
            });
            $(".buy-mask").click(function () {
                $(".buy-unfold-frame").hide();
                $(".buy-mask").hide();
                $(".buy-fold-frame").show();

                isPager = true;
            });

            $('#reduce').click(function () {
                var result = $("#number").val();
                if (result == 1) {
                    return false;
                } else {
                    var number = parseInt(result) - 1;
                    //$("#number").val(number);
                    //$("#total_price").html($("#hidden_cardprice").val() * number);
					getTotalPrice(number);
                }
            });

            $('#add').click(function () {
                var result = $("#number").val();
                if (result == 999) {
                    return false;
                } else {
                    var number = parseInt(result) + 1;
                    //$("#number").val(number);
                    //$("#total_price").html($("#hidden_cardprice").val() * number);
					getTotalPrice(number);
                }
            });

            $(".goods-detail-frame .goods-detail-content .btn-close").click(function () {
                $(".goods-detail-frame").hide();
                isDetailShow=false;

                isPager = true;
            });



			getTotalPrice($("#number").val());
        });

		function getTotalPrice(number){
			$("#number").val(number);
			var totalPrice = $("#hidden_cardprice").val() * number;


            $("#total_price").html(totalPrice.toFixed(0));

		}

        var isDetailShow=false;
        //弹出隐藏层
        function showGoodInfo(title, msg) {
            $(".goods-detail-frame").show();
            $("#goods_name").text(title);
            $("#goods_detail").html(msg);

            isDetailShow=true;
            isPager = false;
        }


        function createOrder(){
            var data = {};
            data.cardid = $("#hidden_cardid").val();
            data.count = $("#number").val();
            var re = returnjson("<?=Url::to(["wx-biz/create-card-order-handle"])?>", data);
            if (re.flag == 1) {
//                alert(re.order_code);
                window.location.href = "<?=Url::to(["wx-pay/wx-card-order-form"]);?>?order_code="+re.order_code ;
            } else {

                alert(re.msg);
                return false;
             }
        }
        function callPay() {

            window.location.href = "<?=Url::to(["wx-pay/wx-card-order-form"]);?>?code=" ;
            return;
        }


        //获取产品详情
        function getGoodInfo(card_id, good_code, isShowStock) {
            var data = {};
            data.isShowStock = isShowStock;
            data.good_code = good_code;
            data.card_id = card_id;

            returnjson("<?=Url::to(["wx-biz/get-good-handle"])?>", data, true, function(re){
                if (re.flag == 1) {
                    showGoodInfo(re.good.GOODS_NAME, re.good.GOODS_DETAIL_HTML);
                } else {
                    alert(re.msg);
                    return false;
                }
            });
        }

        var goodsList = <?=json_encode($goods) ?>;
        function doBack(){
            history.go(-1);
        }

        //        $(function($){
        //            var isbuy=$("#hidden_isbuy").val();
        //
        //            if(isbuy==0){
        //                //不购买
        //                $('.ma_top').hide();
        //            }
        //        });
    </script>
    <title>挑选礼物</title>

</head>

<body>
<input type="hidden" id="hidden_cardid" value="<?=$card['ID']?>"/>
<input type="hidden" id="hidden_cardprice" value="<?=$card['PRICE']?>"/>
<!--<input type="hidden" id="hidden_isbuy" value="--><? //=$isbuy?><!--"/>-->

<div class="wrapper">
    <div class="page">
        <img style="width: 100%;" tag="<?= $card['CARD_TWO'] ?>" src="<?= $web ?>/img/wx/default_goods_show.png">
    </div>
	<?php
	for($i=0; $i<sizeof($goods); $i++){
		$good=$goods[$i];
	?>
	<div class="page">
        <img style="width: 100%;" src="<?= $web ?>/img/wx/default_goods_show.png" onclick="getGoodInfo('<?=$card['ID']?>','<?=$good['GOODS_CODE']?>', 0)">
    </div>
	<?php
	}
	?>
	<div class="page">
        <img style="width: 100%;" tag="<?= $card['CARD_THREE'] ?>" src="<?= $web ?>/img/wx/default_goods_show.png" onclick="doBack()">
    </div>
</div>
<div class="nav-panel">
    <div class="scroll-btn up">
    </div>
    <div class="scroll-btn down">
    </div>
    <nav>
        <ul>
            <li class="nav-btn active"></li>
			<?php
			for($i=0; $i<sizeof($goods); $i++){
			?>
            <li class="nav-btn"></li>
			<?php
			}
			?>
			<li class="nav-btn"></li>
        </ul>
    </nav>
</div>

<a class="buy-fold-frame" href="#">
    <div style="background-color: #ffffff; opacity:0.5; width: 100%; height: 0.5em; position: absolute; top: 0; border-top: 1px #e8e8e8 solid;"></div>
    <div style="position: absolute; top: 0; width: 100%; height: 0.5em;">
        <div style="line-height: 0.4em; height: 0.4em;">
            <div style="float: left; color: #999999; margin-left: 0.1em; margin-top:0.1em;"><label style="font-size: 0.13em; float: left;">朵拉价：</label></div>
            <div style="float: left; color: #d6000f; margin-top:0.115em;"><label style="font-size: 0.12em; float: left;">¥</label></div>
            <div style="color: #d6000f; float: left; margin-left:0.02em; margin-top:0.065em;">
                <label style="font-size: 0.26em; float: left;"><?= floatval($card['PRICE']) ?></label></div>
            <div style="margin-right: 0.1em; float: right; width: 1.15em; height: 0.45em;">
                <div  style="margin-top:0.09em;margin-left: auto; margin-right: auto; width: 1.01em; height: 0.335em; background-size: cover; background-image: url('<?= $web ?>/img/wx/card_list_img/ma_top.png');"></div>
            </div>

        </div>
    </div>

</a>
<div class="buy-mask"></div>
<div class="buy-unfold-frame">
    <table width="100%" cellspacing="0" cellpadding="0" border="0"
           style=" background-color: #ffffff;">
        <tr style="height: 0.34em; line-height: 0.34em;">
            <td style="width: 1em; text-align: left; padding-left:0.2em; border-bottom: 1px #cccccc solid; border-top: 1px #cccccc solid; background-color: #ffffff;">
                <label style="font-size: 0.14em; float: left; width: 100%; color: #d6000f;">购买数量</label>
            </td>
            <td style="width: 0.45em; border-bottom: 1px #cccccc solid; border-top: 1px #cccccc solid; background-color: #ffffff;">
                <div id="reduce" class="reduce-icon" style="background-image: url('<?= $web ?>/img/wx/card_list_img/remove.png');"></div>
            </td>
            <td style="width: 0.4em; height: 0.34em; color:#cccccc; border-bottom: 1px #cccccc solid; border-top: 1px #cccccc solid; background-color: #ffffff;">
                <input value="1" id="number"
                       style="float: left; width: 100%; height: 95%; margin-top: 1px; border-bottom: none; text-align: center; border-top: none; border-left: 1.5px #cccccc solid; border-right: 1.5px #cccccc solid; ">
            </td>
            <td style="width: 0.45em; border-bottom: 1px #cccccc solid; border-top: 1px #cccccc solid; background-color: #ffffff;">
                <div id="add" class="add-icon" style="background-image: url('<?= $web ?>/img/wx/card_list_img/add.png');"></div>
            </td>
        </tr>
        <tr>
            <td colspan="4">
                <div style="line-height: 0.45em; margin-top: 0.1em; height: 0.6em;">
                    <div style="float: left; color: #999999; margin-left: 0.1em; margin-top:0.1em;"><label style="font-size: 0.13em; float: left;">价格合计为：</label></div>
					<div style="float: left; color: #d6000f; margin-top:0.115em;"><label style="font-size: 0.12em; float: left;">¥</label></div>
                    <div style="color: #d6000f; float: left; margin-left:0.02em; margin-top:0.065em;" id="div_calc_price">
                        <label id="total_price" style="font-size: 0.26em; float: left;"><?= floatval($card['PRICE']) ?></label></div>
					<div style="color: #666666; float: left; margin-left:0.02em; margin-top:0.1em; display:none;" id="div_calc_price_old">
                        <label id="total_price_old" style="font-size: 0.12em; float: left; text-decoration:line-through;"></label></div>
					<div style="margin-right: 0.05em; float: right; width: 1.15em; height: 0.45em;">
						<div onclick="createOrder()" style="margin-top:0.09em;margin-left: auto; margin-right: auto; width: 1.01em; height: 0.335em; background-size: cover; background-image: url('<?= $web ?>/img/wx/card_list_img/btn-wx-pay.png?t=1');"></div>
					</div>
					<!--
                    <a href="#"
                       style="margin-right: 0.2em; color: white; background-color:#09bb07; border-radius: 3px; float: right; width: 1.15em; height: 0.45em;"
                       ><label style="font-size: 0.16em; float: left; text-align: center; width: 100%;">立即支付</label></a>-->
                </div>
            </td>
        </tr>
		<tr>
            <td colspan="4">
                <div id="scene_16" style="line-height: 0.3em; height: 0.3em; border-top:1px #cccccc solid;color: #666666; display:none;">
					<label style="font-size: 0.13em; float: left; text-align:center; width:100%;">足额100减50</label>
                </div>
            </td>
        </tr>
    </table>
</div>

<div class="goods-detail-frame">
    <div class="goods-detail-mask"></div>
    <div class="goods-detail-content">
        <div style="height: 0.34em;">
            <a href="#" class="btn-close" style="background-image: url('<?= $web ?>/img/wx/card_list_img/btn-close.png');"></a>
        </div>
        <div style="height: 0.42em; border-bottom: 1px #cccccc solid; background-color: #ffffff;">
            <div class="goods-name-text">
                <div id="goods_name" style="font-size: 0.16em;">商品名称</div>
            </div>
        </div>
        <div id="goods_detail_frame" style="height: 3.6em; background-color: #ffffff; overflow: auto;">
            <div id="goods_detail" class="content-frame">
            </div>
        </div>
    </div>
</div>

</body>
</html>

